<?php

namespace app\common\model;

/**
 * [Gatherreg  活动报名表]
 * @author [C。]
 * @return html
 */
class Gatherreg extends Base
{
    protected $name = 'gatherreg';

    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getlists($map,$from = 0, $size = 5,$fields='*')
    {
        $order = ['gr.id' => 'desc'];
        $join = [
            ['app_gather g','g.id = gr.gather_id'],
        ];
        $result =  $this->field($fields)
            ->alias('gr')
            ->join($join)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据条件获取总数
     * @param array $param
     */
    public function getCountes($map) {
        $join = [
            ['app_gather g','g.id = gr.gather_id'],
        ];
        $result =  $this
            ->alias('gr')
            ->join($join)
            ->where($map)
            ->count();

        return $result;
    }
    /**
     * 根据条件获取总数
     * @param array $param
     */
    public function getCount($map) {
        return $this->where($map)->count();
    }
    /**
     * 根据条件获取报名记录
     * @param array $param
     */
    public function getGatherregByCondition($map,$from = 0, $size = 5,$field = '*') {
        $order = ['gr.id' => 'desc'];
        $join1 = [
            ['app_gather g','g.id = gr.gather_id']
        ];
        $join2 = [
            ['app_member m','m.id = gr.memid']
        ];
        $join3 = [
            ['app_company c','c.id = g.comid']
        ];
        return $this->field($field)
            ->alias('gr')
            ->join($join1)
            ->join($join2)
            ->join($join3)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();
    }
    /**
     * 根据条件获取总数
     * @param array $param
     */
    public function getCounts($map) {
        $join1 = [
            ['app_gather g','g.id = gr.gather_id']
        ];
        $join2 = [
            ['app_member m','m.id = gr.memid']
        ];
        return $this->alias('gr')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->count();
    }
    /**
     * 根据条件获取报名记录
     * @param array $param
     */
    public function getList($map) {
        $order = ['gr.id' => 'desc'];
        $join1 = [
            ['app_gather g','g.id = gr.gather_id']
        ];
        $join2 = [
            ['app_member m','m.id = gr.memid']
        ];
        return $this->field('gr.id,gr.addtime,gr.gather_id,g.title,g.starttime,g.maxnum,m.tel,m.username,gr.name,gr.tel btel,gr.cate,gr.islocal,gr.gotime,gr.job,gr.education,gr.animal,gr.emergency_name,gr.emergency_tel,gr.is_buddhist,gr.buddhist_content,gr.remark,gr.know,gr.referrer')
            ->alias('gr')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->order($order)
            ->select();
    }
}